<#--生成选项-->
<#macro generateOption indent modelInfo>
${indent}@CommandLine.Option(names = {<#if modelInfo.abbr??>"-${modelInfo.abbr}",</#if> "--${modelInfo.fieldName}"},arity = "0..1",interactive = true,<#if modelInfo.description??>description = "${modelInfo.description}"</#if>,echo = true)
${indent}private ${modelInfo.type} ${modelInfo.fieldName}<#if modelInfo.defaultValue??> = ${modelInfo.defaultValue?c}</#if>;
</#macro>
<#--生成命令调用-->
<#macro generateCommand indent modelInfo>
${indent}System.out.println("请输入${modelInfo.groupName}配置");
${indent}CommandLine ${modelInfo.groupKey}CommandLine = new CommandLine(${modelInfo.type}Command.class);
${indent}${modelInfo.groupKey}CommandLine.execute(${modelInfo.allArgsStr});
</#macro>
package ${basePackage}.cli.command;

import cn.hutool.core.bean.BeanUtil;
import ${basePackage}.generator.MainGenerator;
import ${basePackage}.model.DataModel;
import lombok.Data;
import picocli.CommandLine;

import java.util.concurrent.Callable;

/**
* @author ${author}
* 代码生成器的核心命令，作用是接收参数生成代码
*/
@Data
@CommandLine.Command(name = "generator",description = "生成代码",mixinStandardHelpOptions = true)
public class GeneratorCommand implements Callable {
<#list modelConfig.models as modelInfo>
    <#--有分组-->
    <#if modelInfo.groupKey??>
    /**
    * ${modelInfo.groupName}
    */
    static DataModel.${modelInfo.type} ${modelInfo.groupKey} = new DataModel.${modelInfo.type}();

    @CommandLine.Command(name = "${modelInfo.groupName}",description = "${modelInfo.description}")
    @Data
    public static class ${modelInfo.type}Command implements Runnable{
        <#list modelInfo.models as subModelInfo>
            <@generateOption indent="        " modelInfo=subModelInfo/>
        </#list>
        @Override
        public void run(){
        <#list modelInfo.models as subModelInfo>
        ${modelInfo.groupKey}.${subModelInfo.fieldName} = ${subModelInfo.fieldName};
        </#list>
    }
}
        <#else>
        <@generateOption indent="    " modelInfo=modelInfo/>
    </#if>
</#list>
    <#--生成调用方法-->
    @Override
    public Object call() throws Exception {
    <#list modelConfig.models as modelInfo>
        <#if modelInfo.groupKey??>
            <#if modelInfo.condition??>
        if(${modelInfo.condition}){
            <@generateCommand indent="            " modelInfo=modelInfo/>
        }
                <#else>
                <@generateCommand indent="        " modelInfo=modelInfo/>
            </#if>
        </#if>
    </#list>
        DataModel dataModel = new DataModel();
        //属性拷贝
        BeanUtil.copyProperties(this,dataModel);
<#list modelConfig.models as modelInfo>
        <#if modelInfo.groupKey??>
        dataModel.${modelInfo.groupKey} = ${modelInfo.groupKey};
        </#if>
</#list>
        System.out.println("配置信息:"+dataModel);
        //生成代码
        MainGenerator.doGenerator(dataModel);
        return 0;
    }
}
